# !/usr/bin/python
# -*- coding: utf-8 -*-

# mediaplex
# multimedia platform
#
# this file is licensed under the MIT license
# read "LICENSE.MIT" in the root of this distribution

__authors__ = 'Jan Jokela <janjokela@gmail.com>'
__description__ = 'Configuration generic interface'

import backends

config = None

class Generic:
    def __init__(self, backend):
        """ Creates a new generic configuration object
        
        the conf is structured this way:
        [section]
                     option: value
        example:
        > [core.graphics]
        >     fullscreen: 1
        > [plugins.music.playback]
        >     backend: gstreamer   
        
        :backend (string) -- the configuration backend
        """
        self.backend = backend
        self.backends = {
                        'configparser':backends.ConfParser,
                        'gconf':backends.GConf,
                        }
        
    def get_option(self, section, option):
        """
        :section (string) -- the [section] in the conf file
        :option (string) -- the key in the [section]
        :type (string) -- how to interpret the value as
                          str, int, float, boolean, list.
                          raw values are str.                     
        """
        return self.backends[backend].get_option(section, option, type='str')
    
    def set_option(self, section, option, value):
        """
        :section (string) -- the [section] in the conf file
        :option (string) -- the key in the [section]
        :value (string) -- the value we want to give the option                   
        """
        return self.backends[backend].set_option(section, option, value)
    
